const tree = {
    name: 'root',
    children: [
        {
            name: 'c1',
            children: [
                {
                    name: 'c11',
                    children: []
                },
                {
                    name: 'c12',
                    children: []
                }
            ]
        },
        {
            name: 'c2',
            children: [
                {
                    name: 'c21',
                    children: []
                },
                {
                    name: 'c22',
                    children: []
                }
            ]
        }
    ]
}
// * 打印 name
let res = []
function traverse(tree) {

    const {name,children} = tree
    res.push(name)
    if (children) {
        children.forEach(item => {
            traverse(item)
        })
    }
}
traverse(tree)
console.log(res)
